//
//  NSString+ZHWSHA_1.m
//  24-加密
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 ZHW. All rights reserved.
//

#import "NSString+ZHWSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (ZHWSHA_1)
- (NSString *)stringWithSHA_1 {
    const char *cString = [self UTF8String];
    // 求长度
    CC_LONG len = (CC_LONG)strlen(cString);
    // SHA1转换
    unsigned char bytes[CC_SHA1_DIGEST_LENGTH];
    CC_SHA1(cString, len, bytes);
    NSMutableString *finalSHA1 = [NSMutableString string];
    for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x", bytes[i]];
    }
    return finalSHA1;
}
@end
